package xiaodou.modules.importantFans
{
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;

	public class ImportantFansModel extends EventDispatcher
	{
		private var fans:Dictionary;
		public function ImportantFansModel()
		{
			fans = new Dictionary();
		}
		
		public function addFans(idArr:Array):void
		{
			for each (var id:* in idArr) 
			{
				fans[id] = true;
			}
			dispatchEvent(new ImportantFansEvent(ImportantFansEvent.FANS_ADDED, idArr));
		}
		
		public function removeFans(idArr:Array):void
		{
			var data:Array = [];
			for each (var id:* in idArr) 
			{
				if(fans[id] == true)
				{
					data.push(id);
					delete fans[id];
				}
			}
			dispatchEvent(new ImportantFansEvent(ImportantFansEvent.FANS_REMOVED, data));
		}
		
		public function isImportantFans(id:*):Boolean
		{
			return fans[id] == true;
		}
		
		public function get importantFansArr():Array
		{
			var result:Array = [];
			for(var id:* in fans) 
			{
				result.push(id);
			}
			result.sort(Array.NUMERIC);
			return result;
			
		}
	}
}